<template>
  <login @forget="onForget" @success="onSuccess"></login>
  <pwd-set ref="setRef" @success="onSetSuccess" />
  <pwd-code ref="codeRef" @success="onCodeSuccess" />
</template>

<script setup>
  import login from './components/login.vue'
  import pwdSet from '@/components/pwd/set.vue'
  import pwdCode from '@/components/pwd/code.vue'
  import { userStore } from '@/store/user'
  import router from '@/router'
  import { ref } from 'vue'

  const [setRef, codeRef] = [ref(), ref()]

  function onForget() {
    codeRef.value.show(true)
  }
  function onSuccess() {
    if (!userStore().info.pwdFlag) {
      setRef.value.show(userStore().info.phone, true)
    } else {
      router.goRoot()
    }
  }
  function onSetSuccess() {
    if (userStore().isLogin) {
      router.goRoot()
    }
  }
  function onCodeSuccess(phone) {
    setRef.value.show(phone)
  }
</script>
<style lang="scss" scoped></style>
